<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script type="text/javascript">
        function updateProcess() {
            var msg = document.getElementById('msg')
            var input = document.createElement('input')
            input.type = 'file'
            input.onchange = function () {
                msg.innerText = ''
                let fd = new FormData()
                fd.append('file', input.files[0])
                let xhr = new XMLHttpRequest()
                xhr.open('POST', '/api/update')
                xhr.upload.onprogress = function (event) {
                    if (event.lengthComputable) {
                        msg.innerText = '上传进度：' + Math.round(event.loaded / event.total * 100) + '%'
                    }
                }
                xhr.onload = function () {
                    msg.innerHTML = xhr.responseText
                }
                xhr.send(fd)
            }
            input.click()
        }
        function resetProcess() {
            var msg = document.getElementById('msg')
            msg.innerHTML = ''
            var xhr = new XMLHttpRequest()
            xhr.open('POST', '/api/reset')
            xhr.onload = function () {
                msg.innerHTML = xhr.responseText
            }
            xhr.send(null)
        }
        function downloadlogs() {
            let ele = document.createElement('a')
            ele.href = '/api/downlogs'
            ele.download = 'logs.zip'
            ele.click()
        }
        function clearlogs() {
            var msg = document.getElementById('msg')
            msg.innerHTML = ''
            var xhr = new XMLHttpRequest()
            xhr.open('POST', '/api/clearlogs')
            xhr.onload = function () {
                msg.innerHTML = xhr.responseText
            }
            xhr.send(null)
        }
        function clearMessage() {
            var msg = document.getElementById('msg')
            msg.innerHTML = ''
        }
    </script>
    <title>程序更新</title>
</head>

<body>
    <div>
        <button onclick="updateProcess()">上传更新文件</button>
        <button onclick="resetProcess()">重启当前程序</button>
        <button onclick="downloadlogs()">下载日志</button>
        <button onclick="clearlogs()">清空日志</button>
        <button onclick="clearMessage()">清空msg</button>
    </div>
    <div id="msg"></div>
</body>

</html>
